package xyz.naokeziteng.leetcode;

import java.util.Arrays;

/**
 * @author hawk
 * @date 2022/8/22
 * @desc 75题，颜色排序
 **/
public class SortColors {

    public static void sortColors(int[] nums) {
        int i = 0;
        int lt = 0;
        int gt = nums.length - 1;
        while (i <= gt) {
            if (nums[i] == 0) {
                swap(nums, i, lt);
                lt++;
                i++;
            } else if (nums[i] == 2) {
                swap(nums, i, gt);
                gt--;
            } else {
                i++;
            }
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
//        int[] arr = {2, 0, 1};
//        sortColors(arr);
//        System.out.println(Arrays.toString(arr));
        int[] arr = new int[3];
        System.out.println(Arrays.toString(arr));
        int i = 0;
        System.out.println(i);
        arr[i++] = 1;
        System.out.println(i);
        System.out.println(Arrays.toString(arr));

    }
}
